#ifndef IPORTABLESOCKET_H
#define IPORTABLESOCKET_H
#include "portablelibrary.h"
#include "portablesocketmessage.h"

#include <string>
#include <iostream>

class IPortableSocket
{
 public:
  enum SockType 
  {
    TCP, 
    UDP
  };
  
  virtual bool connect(std::string const &remote, unsigned int port, SockType type = UDP) = 0;
  virtual bool createServerSocket(IPortableSocket::SockType type, unsigned int port) = 0;
  virtual bool createClientSock() = 0;
  virtual IPortableSocket *waitForClient() = 0;
  virtual void setMaxClient(unsigned int nb) = 0;
  virtual unsigned int getTotalNumberConnectedClient() const = 0;
  virtual unsigned int getNumberConnectedClient() const = 0;
  virtual void send(std::string const &str) = 0;
  virtual void send(const char *str, unsigned int len) = 0;
  virtual void send(IPortableSocket *sock, std::string const & str) = 0;
  virtual void send(IPortableSocket *sock, const char *str, unsigned int len) = 0;
  virtual unsigned int read(char *buf, unsigned int size) = 0;
  virtual unsigned int read(IPortableSocket *sock, char *buf, unsigned int size) = 0;
  virtual void disconnect() = 0;
  virtual bool isServerSock() const = 0;
  virtual std::string const &getIp() const = 0;
  virtual unsigned short getPort() const = 0;
};

class APortableSocket : public IPortableSocket
{
 protected:
  SockType		_type;
  static int		_total_client_connected;
  int			_client_connected;
  int			_max_client;
  unsigned short	_port;
};

#ifdef OS_WINDOWS
#include "windowssocket.h"
typedef class Win32Socket PortableSocket;
#elif defined OS_UNIX
#include "unixsocket.h"
typedef class UNIXSocket PortableSocket;
#endif

#endif // IPORTABLESOCKET_H
